package com.view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class admin_window {
    private JFrame jFrame = new JFrame("图书管理系统");
    private JButton searchBookButton = new JButton("查询图书");
    private JButton searchRecordsButton = new JButton("查询记录");
    private JButton addUserButton = new JButton("添加用户");
    private JButton deleteUserButton = new JButton("删除用户");
    private JButton myInfoButton = new JButton("我的信息");

    private Panel buttonPanel = new Panel();
    private Panel mainPanel = new Panel();

    private ScrollPane searchBookPane = new ScrollPane();
    private ScrollPane searchRecordsPane = new ScrollPane();
    private ScrollPane addUserPane = new ScrollPane();
    private ScrollPane deleteUserPane = new ScrollPane();
    private ScrollPane myInfoPane = new ScrollPane();

    private JLabel searchBookLabel = new JLabel("searchBookLabel");
    private JLabel searchRecordLabel = new JLabel("searchRecord");
    private JLabel addUserLabel = new JLabel("addUser");
    private JLabel deleteUserLabel = new JLabel("deleteUser");
    private JLabel myInfoLabel = new JLabel("manageUser");

    private CardLayout cardLayout = new CardLayout();



    public void init(String username,String password) {
        jFrame.setBounds(200,100,1000,600);
        jFrame.setLayout(new BorderLayout());
        mainPanel.setLayout(cardLayout);

        //添加按钮至按钮栏
        buttonPanel.add(searchBookButton);
        buttonPanel.add(searchRecordsButton);
        buttonPanel.add(addUserButton);
        buttonPanel.add(deleteUserButton);
        buttonPanel.add(myInfoButton);

        //添加主页面
        mainPanel.add("查询图书",searchBookPane);
        mainPanel.add("查询记录",searchRecordsPane);
        mainPanel.add("添加用户",addUserPane);
        mainPanel.add("删除用户",deleteUserPane);
        mainPanel.add("我的信息",myInfoPane);

        //添加页面内容
        //searchBookPane.add(searchBookLabel);
        searchBookPane.add(new com.view.adminMenu.serchBookMenu().init());
        //searchRecordsPane.add(searchRecordLabel);
        searchRecordsPane.add(new com.view.adminMenu.searchRecordsMenu().init());
        //addUserPane.add(addUserLabel);
        addUserPane.add(new com.view.adminMenu.addUser().init());
        //deleteUserPane.add(deleteUserLabel);
        deleteUserPane.add(new com.view.adminMenu.deleteUser().init());
        //myInfoPane.add(myInfoLabel);
        myInfoPane.add(new com.view.adminMenu.myInfoMenu().init(jFrame,username, password));

        //创建事件监听器，监听按钮动作
        ActionListener listener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String actionCommand = e.getActionCommand();//字符串为按键上的文字
                switch (actionCommand) {
                    case "查询图书" :
                        cardLayout.first(mainPanel);
                        System.out.println("clicked 查询图书");
                        break;
                    case "查询记录" :
                        cardLayout.show(mainPanel,"查询记录");
                        System.out.println("clicked 查询记录");
                        break;
                    case "添加用户" :
                        cardLayout.show(mainPanel,"添加用户");
                        System.out.println("clicked 添加用户");
                        break;
                    case "删除用户" :
                        cardLayout.show(mainPanel,"删除用户");
                        System.out.println("clicked 删除用户");
                        break;
                    case "我的信息" :
                        cardLayout.last(mainPanel);
                        System.out.println("clicked 我的信息");
                        break;
                }
            }
        };

        //为按钮添加监听器
        searchBookButton.addActionListener(listener);
        searchRecordsButton.addActionListener(listener);
        addUserButton.addActionListener(listener);
        deleteUserButton.addActionListener(listener);
        myInfoButton.addActionListener(listener);

        //组装jFrame
        jFrame.add(mainPanel,BorderLayout.CENTER);
        jFrame.add(buttonPanel,BorderLayout.SOUTH);
        jFrame.setVisible(true);



    }

//    public static void main(String[] args) {
//        new com.view.admin_window().init("manager1","456");
//    }
}
